
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
/**
 *
 * @author Aparna
 */
public class RunSwitchBoard {
    public static void main(String[] args) throws Exception {
        if (args.length != 3) {
            System.err.println("Usage:  RunGoogle querySrc urlDest pageCount");
            System.exit(1);
        }
        int maxPage = Integer.parseInt(args[2]);
        BufferedReader read = new BufferedReader(new FileReader(args[0]));
        PrintWriter out = new PrintWriter(new FileWriter(args[1]));
        SwitchBoard google = new SwitchBoard(2500, 2500, 2500, 2500);
        String query;
        ArrayList<SearchResult> list;

        query = read.readLine();
        while (query != null) {
            list = google.getResultsWithDelay(query, 1, maxPage);

            for (int c = 0; c < list.size(); c++) {
                out.println(list.get(c).getUrl());
            }

            out.println();
            google.queryDelay();
            
            query = read.readLine();
        }

        out.close();
    }
}



